global input "Q:\dc1prhcmsas01\PU2\data - sas"
global temp "Q:\dc1prhcmsas01\PU2\temp_stata_wr"
global log "Q:\dc1prhcmsas01\PU2\Log - Stata WR"
global output "Q:\dc1prhcmsas01\PU2\data_stata_wr"
global graphs "Q:\dc1prhcmsas01\PU2\graphs_stata_wr"
global tables "Q:\dc1prhcmsas01\PU2\tables_stata_wr"

cd "Q:\dc1prhcmsas01\PU2\Code - Stata WR"
set scheme plotplain
graph set window fontface "Times New Roman"

capture log close
log using "$log/11_table_rd_hires", replace

*Program to estimate regressions
cap program drop save_est
program define save_est 
args name var start

	*Save estimates
	use  "$output/`name'_estimates.dta", clear
	gen se=(ub-beta)/1.96
	keep if event_time==6
	
	local index = `start'
	foreach spec in One-Slope Two-Slope Right-Tail {
		preserve 
		keep if spec=="`spec'"
		
		*Regression Coefficients
		sum beta
		global b`index'_`var'=round(r(mean), 0.001)
		sum se
		global se`index'_`var'=round(r(mean),0.001)
		
		*Baseline characteristics
		sum n
		global n`index'_`var'=string(r(mean), "%10.0fc")
		
		restore 
		local ++index
	}
end 


*Program to estimate regressions
cap program drop save_est2
program define save_est2 
args name var start

	*Save estimates
	use  "$output/`name'_estimates.dta", clear
	gen se=(ub-beta)/1.96
	keep if event_time==6
	
	local index = `start'
	foreach spec in One-Slope-Diff Two-Slope-Diff Right-Slope-Diff {
		preserve 
		keep if spec=="`spec'"
		
		*Regression Coefficients
		sum beta
		global b`index'_`var'=round(r(mean), 0.001)
		sum se
		global se`index'_`var'=round(r(mean),0.001)
		
		*Baseline characteristics
		sum n
		global n`index'_`var'=string(r(mean), "%10.0fc")
		
		restore 
		local ++index
	}
end 
*Table C1
	save_est figc2_base_rd_time base 1 
	save_est figc2_diff_base_rd_time diff 1
	save_est figc2_observe_rd_time observe 1
	save_est2 figc2_base_future_rd_time fut 4
	save_est2 figc2_wage_growth_rd_time growth 4
	save_est2 figc2_separation_rd_time sep 4
	

	
	capture erase "$tables/tableC1.tex"
	file open fh3 using "$tables/tableC1.tex", write replace

	file write fh3 ///
		"\begin{tabular}{@{\hskip\tabcolsep\extracolsep\fill} l cc cc cc cc cc cc}" _n ///
		"\toprule" _n ///
		"&& (1) && (2) && (3) && (4) && (5) && (6) \\" _n ///
		"\midrule" _n ///
		"Base Pay in Previous Job && $b1_base && $b2_base && $b3_base && && &&  \\" _n ///
		" && ($se1_base) && ($se2_base) && ($se3_base) && && &&  \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay from Prev. Job && $b1_diff && $b2_diff && $b3_diff && && &&   \\" _n ///
		" && ($se1_diff) && ($se2_diff) && ($se3_diff) &&  && && \\" _n ///
		"[1em] \\" _n ///
		"Probability Observe Previous Job  && $b1_observe && $b2_observe && $b3_observe &&  && &&  \\" _n ///
		" && ($se1_observe) && ($se2_observe) && ($se3_observe) && &&  && \\" _n ///
		"[1em] \\" _n ///
		"Base Pay After 18 Months && && &&  && $b4_fut && $b5_fut && $b6_fut    \\" _n ///
		" && &&  && && ($se4_fut) && ($se5_fut) && ($se6_fut)  \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay After 18 Months && && &&  && $b4_growth && $b5_growth && $b6_growth    \\" _n ///
		" && &&  && &&  ($se4_growth) && ($se5_growth) && ($se6_growth)  \\" _n ///
		"[1em] \\" _n ///
		"Probability Separate in 18 months && && &&  && $b4_sep && $b5_sep && $b6_sep    \\" _n ///
		" && &&  && && ($se4_sep) && ($se5_sep) && ($se6_sep)  \\" _n ///
		"\midrule" _n ///
		"N && $n1_base && $n2_base && $n3_base && $n4_fut && $n5_fut && $n6_fut \\" _n ///
		"Sample	  && One Slope && Two Slope  && Right Tail  && One Slope && Two Slope && Right Tail \\" _n ///
		"\bottomrule" _n ///
		"\end{tabular}" _n
		
	file close fh3 
	macro drop fh3 
	

	capture erase "$tables/tableC1_short.tex"
	file open fh3 using "$tables/tableC1_short.tex", write replace

	file write fh3 ///
		"\begin{tabular}{@{\hskip\tabcolsep\extracolsep\fill} l cc cc cc cc}" _n ///
		"\toprule" _n ///
		"&& (1) && (2) && (3) && (4) \\" _n ///
		"\midrule" _n ///
		"Base Pay in Previous Job && $b1_base && $b2_base && &&  \\" _n ///
		" && ($se1_base) && ($se2_base)  && &&  \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay from Prev. Job && $b1_diff && $b2_diff && &&   \\" _n ///
		" && ($se1_diff) && ($se2_diff) &&  &&  \\" _n ///
		"[1em] \\" _n ///
		"Probability Observe Previous Job  && $b1_observe && $b2_observe  &&  &&  \\" _n ///
		" && ($se1_observe) && ($se2_observe) && &&  \\" _n ///
		"[1em] \\" _n ///
		"Base Pay After 18 Months  && && && $b4_fut && $b5_fut   \\" _n ///
		" && && && ($se4_fut) && ($se5_fut)  \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay After 18 Months  && && && $b4_growth && $b5_growth    \\" _n ///
		"  && && && ($se4_growth) && ($se5_growth)  \\" _n ///
		"[1em] \\" _n ///
		"Probability Separate in 18 months && && && $b4_sep && $b5_sep    \\" _n ///
		"  && && && ($se4_sep) && ($se5_sep)   \\" _n ///
		"\midrule" _n ///
		"N && $n1_base && $n2_base  && $n4_fut && $n5_fut  \\" _n ///
		"Sample	  && One Slope && Two Slope   && One Slope && Two Slope \\" _n ///
		"\bottomrule" _n ///
		"\end{tabular}" _n
		
	file close fh3 
	macro drop fh3 
	
	*Table C1
	save_est figc2_log_base_rd_time base 1 
	save_est figc2_diff_base_rd_time diff 1
	save_est figc2_observe_rd_time observe 1
	save_est2 figc2_log_base_future_rd_time fut 4
	save_est2 figc2_wage_growth_rd_time growth 4
	save_est2 figc2_separation_rd_time sep 4

	capture erase "$tables/tableC1_short_log.tex"
	file open fh3 using "$tables/tableC1_short_log.tex", write replace

	file write fh3 ///
		"\begin{tabular}{@{\hskip\tabcolsep\extracolsep\fill} l cc cc cc cc}" _n ///
		"\toprule" _n ///
		"&& (1) && (2) && (3) && (4) \\" _n ///
		"\midrule" _n ///
		"Log Base Pay in Previous Job && $b1_base && $b2_base && &&  \\" _n ///
		" && ($se1_base) && ($se2_base)  && &&  \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay from Prev. Job && $b1_diff && $b2_diff && &&   \\" _n ///
		" && ($se1_diff) && ($se2_diff) &&  &&  \\" _n ///
		"[1em] \\" _n ///
		"Probability Observe Previous Job  && $b1_observe && $b2_observe  &&  &&  \\" _n ///
		" && ($se1_observe) && ($se2_observe) && &&  \\" _n ///
		"[1em] \\" _n ///
		"Log Base Pay After 18 Months  && && && $b4_fut && $b5_fut   \\" _n ///
		" && && && ($se4_fut) && ($se5_fut)  \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay After 18 Months  && && && $b4_growth && $b5_growth    \\" _n ///
		"  && && && ($se4_growth) && ($se5_growth)  \\" _n ///
		"[1em] \\" _n ///
		"Probability Separate in 18 months && && && $b4_sep && $b5_sep    \\" _n ///
		"  && && && ($se4_sep) && ($se5_sep)   \\" _n ///
		"\midrule" _n ///
		"N && $n1_base && $n2_base  && $n4_fut && $n5_fut  \\" _n ///
		"Sample	  && One Slope && Two Slope   && One Slope && Two Slope \\" _n ///
		"\bottomrule" _n ///
		"\end{tabular}" _n
		
	file close fh3 
	macro drop fh3 
log close
